package guava.collection;

import com.google.common.collect.ArrayListMultimap;
import com.google.common.collect.Multimap;

/**
 * MultiMap
 *
 * @author nanxin.chen
 * @date 2015/9/7
 */
public class MultiMapTest {
    public static void main(String[] args) {
        MultiMapTest mmTest = new MultiMapTest();
        Multimap<String,String> multimap = mmTest.getMultimap();

        System.out.println("get value by key from multimap:" + multimap.get("lower"));
        System.out.println("get multimap's key set:" + multimap.keySet());
        System.out.println("get multimap's keys:" + multimap.keys());
        System.out.println("get multimap's values:" + multimap.values());

        multimap.remove("upper","D");
        System.out.println("remove upper D:"+multimap.values());
        multimap.removeAll("upper");
        System.out.println("remove all upper:"+multimap.values());


    }

    private Multimap<String,String> getMultimap(){
        //Map<String, List<String>>
        // lower -> a, b, c, d, e
        // upper -> A, B, C, D

        Multimap<String,String> multimap = ArrayListMultimap.create();

        multimap.put("lower", "a");
        multimap.put("lower", "b");
        multimap.put("lower", "c");
        multimap.put("lower", "d");
        multimap.put("lower", "e");

        multimap.put("upper", "A");
        multimap.put("upper", "B");
        multimap.put("upper", "C");
        multimap.put("upper", "D");
        return multimap;
    }
}
